package servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.ItemAttr;
import pojo.UserAttr;

import dao.ItemDao;
import dao.PollDao;

public class PollList extends ServletTemplate{
    /**
     * 执行POST操作 
     */
    public void doPost(HttpServletRequest request,
                         HttpServletResponse response) throws IOException, ServletException{
        super.doPost(request, response);
       
        if(false == this.isLogin()) {
            this.setRequestAttr("errorInfo", "非法登陆！");
            this.forward("hint.jsp");
            return ;
        }
        
        ItemDao itemDao     = new ItemDao();
        if(true == itemDao.select()) {
            ArrayList<ItemAttr> items     = itemDao.fetchAll();
            this.setRequestAttr("items", items);
            this.setRequestAttr("totallPoll", itemDao.getTotalPoll());
            UserAttr userAttr    = (UserAttr)this.getSessionAttr("userAttr");
            boolean isPoll      = new PollDao().isPoll(userAttr.getUserId());
            this.setSessionAttr("isPoll", isPoll);
        }
        this.forward("polllist.jsp");
    }
}
